#include "server.hpp"

std::string handler(const std::string& str)
{
    std::string s = "server get message: ";
    s += str;
    std::cout << s << std::endl;
    return s;
}

std::string execute(const std::string& cmd)
{
    //safecheck 不想执行的命令安全检查
    FILE* fp = popen(cmd.c_str(), "r");
    if (fp == nullptr)
    {
        perror("popen");
        return "error";
    }

    string ret;
    char buff[4096];
    while (true)
    {
        char *ok = fgets(buff, sizeof(buff), fp);
        if (ok == nullptr)
        {
            break;
        }

        ret += buff;
    }

    pclose(fp);
    return ret;
}

int main()
{
    server ser;
    ser.init();
    ser.run(handler);
    return 0;
}